package com.yumis.service.modules.car.service.Impl;

import com.yumis.service.common.enums.HttpState;
import com.yumis.service.common.exception.GlobalException;
import com.yumis.service.common.vo.Response;
import com.yumis.service.model.pojo.CarTaskTime;
import com.yumis.service.modules.car.mapper.CarTaskTimeMapper;
import com.yumis.service.modules.car.service.CarTaskTimeService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Slf4j
@Service
public class CarTaskTimeServiceImpl implements CarTaskTimeService {
    @Resource
    private CarTaskTimeMapper carTaskTimeMapper;
    @Override
    public void addCarTaskTime(CarTaskTime carTaskTime) {
        carTaskTime.setCreateTime((int) (System.currentTimeMillis()/1000));
        carTaskTime.setUpdateTime((int) (System.currentTimeMillis()/1000));
        int i=carTaskTimeMapper.insertSelective(carTaskTime);
        if (i !=1){
            throw new GlobalException(Response.buildResponse(HttpState.CREATED_FAILED));
        }
    }

    @Override
    public void deleteCarTaskTimeById(Long id) {
        int i=carTaskTimeMapper.deleteByPrimaryKey(id);
        if (i !=1){
            throw new GlobalException(Response.buildResponse(HttpState.DELETE_ERROR));
        }
    }

    @Override
    public CarTaskTime queryTaskTimeById(Long id) {
        CarTaskTime carTaskTime=carTaskTimeMapper.selectByPrimaryKey(id);
        if (carTaskTime ==null || carTaskTime.equals("") ){
            throw new GlobalException(Response.buildResponse(HttpState.DATA_NOT_FOUNT));
        }
        return carTaskTime;
    }

    @Override
    public void updateTaskTime(CarTaskTime carTaskTime) {
        carTaskTime.setUpdateTime((int) (System.currentTimeMillis()/1000));
        int i=carTaskTimeMapper.updateByPrimaryKeySelective(carTaskTime);
        if (i !=1){
            throw new GlobalException(Response.buildResponse(HttpState.UPDATE_ERROR));
        }
    }
}
